# 抖码算法，让算法学习变得简单有趣
# 作者：老汤

fixed_len = int(input())
rows = int(input())

data = []
for i in range(rows):
    data.append(str(input()).split(","))

res, remain_rows = [], rows
# 用于记住每一行遍历到的位置
flags = [0] * rows

while remain_rows > 0:
    for row in range(rows):
        if flags[row] == -1:
            continue

        # 情况一：当前行剩余的元素个数不足 fixed_len
        if flags[row] + fixed_len >= len(data[row]):
            for i in range(flags[row], len(data[row])):
                res.append(data[row][i])
            remain_rows -= 1
            flags[row] = -1
        else:  # 情况二：当前行剩余的元素个数大于 fixed_len
            for i in range(flags[row], flags[row] + fixed_len):
                res.append(data[row][i])
            flags[row] += fixed_len

print(",".join(res))